/**
 * 
 *  纵向思维
 * @param {string[]} strs
 * @return {string}
 */
var longestCommonPrefix = function (strs) {

    if (!strs.length) {
        return ''
    }
    if (strs.length === 1) {
        return strs[0]
    }
    let rslt = ''
    let i = 0

    while (i < strs.length) {
        let c = strs[0][i]
        for (let j = 0; j < strs.length; j++) {
            if (c !== strs[j][i]) {
                return rslt
            }
        }
        rslt += c;
        i++
    }
    return rslt
};

console.log(longestCommonPrefix(["rog", "racecar", "rar"]))